<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<style>
    div{
        width: 300px;
        height: 300px;
        background: tomato;
        margin: 100px;
    }
</style>
<body>
<div></div>
<script>
    var div = document.querySelector('div');
    div.addEventListener('mousemove',function (e) {
        var x = e.pageX - this.offsetLeft;
        var y = e.pageY - this.offsetTop;
        this.innerHTML = 'X坐标为：'+x+'Y坐标为：'+y;
    })
</script>
</body>
</html>